package com.huaxinkai.mobile.socket;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;

/**
 * url获取web页面内容
 * @author liuzh
 * @date 2017年1月14日下午10:17:10
 */
public class UrlGetWebContent {

	public static void main(String[] args) {
		try {
			URL url = new URL("http://www.13ij.com");
			//通过url的openstream获取url对象所表示的资源的字节输入流
			InputStream is = url.openStream();
			//将字节流转换城子夫流
			InputStreamReader isr =  new InputStreamReader(is,"UTF-8");
			//为字符流添加缓冲
			BufferedReader br = new BufferedReader(isr);
			String data = br.readLine();
			while(data != null){
				System.out.println(data);
				data = br.readLine();
			}
			br.close();
			isr.close();
			is.close();
		} catch (MalformedURLException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
		

	}

}
